<template>
  <div class="window" :style="{ width: width + 'px', height: height + 'px' }" v-if="show">
    <div class="title">
      <span class="iconfont icon-guanbi" @click="close"></span>
    </div>
    <div class="body">
        <slot></slot>
    </div>

    <div class="footer">
      <template v-if="(buttons && buttons.length > 0) || showCancel">
        <el-button link @click="close" v-if="showCancel"> 取消 </el-button>
        <el-button
          v-for="(btn, index) in buttons"
          :key="index"
          :type="btn.type"
          @click="btn.click"
        >
          {{ btn.text }}
        </el-button>
      </template>
    </div>
  </div>
</template>

<script setup>
import { defineProps, defineEmits, ref } from "vue";

const props = defineProps({
  width: {
    type: Number,
    required: true,
  },
  height: {
    type: Number,
    required: true,
  },
  buttons: {
    type: Array,
  },
  showCancel: {
    type: Boolean,
    default: true,
  },
  show: {
    type: Boolean,
    default: false,
  }
});

const bodyHeight = props.height - 30 - 50;

const emit = defineEmits(["close"]);
const close = () => {
  emit("close");
}

</script>

<style scoped lang="scss">
.window {
  position: absolute;
  top: 0px;
  left: 0px;
  width: 100%;
  height: calc(100vh - 70px);
  background: #f4f4f4;
  z-index: 50;

  .title {
    height: 30px;
    display: flex;
    align-items: center;
    padding-left: 10px;
    .back{
        font-size: 20px;
        cursor: pointer;
    }
  }
  .body {
    height: calc(100vh - 151px);
    background: white;
    padding: 10px;
    overflow: auto;
  }
  .footer {
    border-top: 1px solid #dddddd;
    text-align: center;
    line-height: 50px;
  }
}
</style>